

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>请输入患者姓名</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/admin/layui-v2.4.5/layui/css/layui.css"  media="all">
  <link rel="stylesheet" href="/admin/css/admin.css"  media="all">
  <link rel="stylesheet" href="/admin/css/template.css"  media="all">

  <style>
    .layadmin-text-center{position: absolute;left: 10px;top: 10px;}
    .layadmin-padding-right20{position: absolute;left: 250px;top: 20px;}
    .layui-card-body{overflow: auto;height:250px;}
    .mybtn{margin-left:560px;}
    .wodediv{margin-left:50px}
    .zuo{float:right;}

    img{border-radius: 10px;height:150px;width:150px;margin-top:30px;}
    body{padding:10px; font-size:14px; background:#66; width:95%; margin:0 auto; font-size:14px; line-height:20px; overflow:hidden;}
    p{margin-bottom:10px;}
    input{border:1px solid #999; padding:5px 10px; margin:0 10px 10px 0;}
  </style>
</head>
<body>
<script src="/admin/layui-v2.4.5/layui/layui.js" charset="utf-8"></script>

<div id="divsub">
    <input class="layui-input-block" placeholder="请输入患者姓名" id="LAY_mark">
    <button class="layui-btn" data-type="haha">提交</button>
    <!--<button class="layui-btn mybtn">一键出库</button>-->

</div>


<div class="layui-col-md6"id="mianban">
<!--  <div class="layui-card">
    <div class="layui-card-body">
<div class="layadmin-contact-box">
<div class="layui-col-md4 layui-col-sm6">
<a href="javascript:;">
<div class="layadmin-text-center">
<img src="/admin/extend/image/character.jpg">
</div>
</a>
</div>
<div class="layui-col-md8 layadmin-padding-right20 layui-col-sm6">
<h3 class="layadmin-title">
<strong>胡歌</strong>
</h3>
  <table class="layui-table" lay-even="" lay-skin="nob">
    <colgroup>
      <col width="200">
      <col width="100">
    </colgroup>
    <thead>
    <tr>
      <th>药品名称</th>
      <th>数量</th>
    </tr>
    </thead>
    <tbody id="tbody">
    <tr>
      <td>贤心</td>
      <td>汉族</td>

    </tr>
    <tr>
      <td>张爱玲</td>
      <td>汉族</td>

    </tr>
    </tbody>
  </table>

</div>
</div>
</div>
</div>-->



</div>


<script>
    // layui.define(function(exports){
layui.use('layer', function(){
  var $ = layui.$
  ,layer = layui.layer
  ,index = parent.layer.getFrameIndex(window.name); //获取窗口索引
/*
    $(document).ready(function () {

    })*/
  var name1;
  var active = {

          haha: function () {
              var name = $('#LAY_mark').val();
              $.ajax({
                  url: '/hospital/nameMedPat',
                  dataType: 'json',
                  type: 'post',
                  dataType: "json",
                  data: JSON.stringify({
                      "name": name
                  }),
                  contentType: "application/json; charset=utf-8",
                  success: function (data) {
                      console.log(data.data.length);
                      if (data.data.length==0){
                          parent.layer.msg('该患者不在取药队列', {shade: 0.3})
                      }
                      $.each(data.data, function (index, item) {
                          name1=item.pat_name;
                          $('#mianban').empty();
                          $('#mianban').append("<div class=\"layui-card\">\n" +
                              "    <div class=\"layui-card-body\">\n" +
                              "<div class=\"layadmin-contact-box\">\n" +
                              "<div class=\"layui-col-md4 layui-col-sm6\">\n" +
                              "<a href=\"javascript:;\">\n" +
                              "<div class=\"layadmin-text-center\">\n" +
                              "<img src=\"/admin/extend/image/1.jpg\">\n" +
                              "</div>\n" +
                              "</a>\n" +
                              "</div>\n" +
                              "<div class=\"layui-col-md8 layadmin-padding-right20 layui-col-sm6\">\n" +
                              "<h3 class=\"layadmin-title\">\n" +
                              "<strong>"+item.pat_name+"</strong>\n" +
                              "</h3>\n" +
                              "  <table class=\"layui-table\" lay-even=\"\" lay-skin=\"nob\">\n" +
                              "    <colgroup>\n" +
                              "      <col width=\"200\">\n" +
                              "      <col width=\"100\">\n" +
                              "      <col width=\"100\">\n" +
                              "    </colgroup>\n" +
                              "    <thead>\n" +
                              "    <tr>\n" +
                              "      <th>药品名称</th>\n" +
                              "      <th>数量</th>\n" +
                              "      <th>单价:元</th>\n" +
                              "    </tr>\n" +
                              "    </thead>\n" +
                              "    <tbody id=\"tbody\">\n" +
                              "\n" +
                              "    </tbody>\n" +
                              "  </table>\n" +
                              "\n" +
                              "</div>\n" +
                              "</div>\n" +
                              "</div>\n" +
                              "</div><p>总价格：<strong>"+item.total+"元</strong></p><button class=\"layui-btn mybtn\"data-type=\"mybutton\" id=\"mybutton\">一键出库</button>");
                          $.each(item.medicine, function (index1, item1) {
                              console.log(item.medicine);
                              console.log(item1);
                              $("#tbody").append("<tr>\n" +
                                  "      <td>"+item1.med_name+"</td>\n" +
                                  "      <td>"+item1.med_count+"</td>\n" +
                                  "      <td>"+item1.med_price+"</td>\n" +
                                  "      \n" +
                                  "    </tr>")

                          });
                      });
                  }

              })
              // parent.layer.iframeAuto(index);
          }
      // }
    /*//在父层弹出一个层
    ,parentPopup: function(){
      parent.layer.msg('Hi, man', {shade: 0.3})
    }
    
    //给父页面传值
    ,setParent: function(){
      var id = '#LAY_layer_iframe_demo'
      ,mark = $('#LAY_mark')
      ,val = mark.val();
      
      if(val === ''){
        mark.focus();
        parent.layer.msg('请填写标记');
        return true;
      }
      
      parent.layer.msg('您将标记 [ ' +val + ' ] 成功传送给了父窗口');
      parent.layui.$(id).text('我被改变了');
      parent.layer.tips('Look here', id, {
        time: 5000
      });
      parent.layer.close(index);
    }*/
    
    
    //在内部关闭iframe
    ,close: function(set){
      parent.layer.close(index);
    }
  }
    $(document).on('click','#mybutton',function(){

        var Arr = new Array();
        $("table").each(function(){  // 获取表格table中，第几个td的文本
            for (var i = 1; i < $(this).find("tr").length; i++) {
                var obj = new Object();
                var sValue1 = $(this).find("tr").eq(i).find("td").eq(0).html();//获取td内容
                obj["name"]=sValue1;
                var sValue2 = $(this).find("tr").eq(i).find("td").eq(1).html();
                obj["count"]=sValue2;
                Arr.push(obj);
            }
console.log(JSON.stringify(Arr));

        })
    $.ajax({
        url: '/hospital/sale/nameClose',
        dataType: 'json',
        type: 'post',
        async: false,
        contentType: "application/json; charset=utf-8",
        data:JSON.stringify({"patname":name1,
            "key":Arr}),
        success: function (e) {
                if (e.code == 1) {
                    parent.layer.msg("出库成功");
                } else {
                    parent.layer.msg("出库失败");
                }
            },
            error: function (e) {
                parent.layer.msg(e);
            }


    })
        parent.layer.close(index);
    });

  $('.layui-btn-container .layui-btn').on('click', function(){
    var othis = $(this)
    ,type = othis.data('type');
    active[type] && active[type].call(this);
  });
    $('#divsub .layui-btn').on('click', function(){
        var othis = $(this)
            ,type = othis.data('type');
        active[type] && active[type].call(this);
    });
});
</script>
</body>
</html>
